package com.iplant.pdm.serviceImpl.dao.fpc;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.pdm.service.po.fpc.FPCCapacity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.stream.Collectors;

public class FPCCapacityDAO extends BaseDAO {

    private static FPCCapacityDAO Instance = null;
    private static Logger logger = LoggerFactory.getLogger(FPCCapacityDAO.class);

    private FPCCapacityDAO() {
        super(FPCCapacity.class);
    }

    public static FPCCapacityDAO getInstance() {
        if (Instance == null)
            Instance = new FPCCapacityDAO();
        return Instance;
    }

    public Map<Integer,FPCCapacity> GetProductCapacityMap(BMSEmployee wLoginUser,int wProductID, int wFactoryID, int wWorkshopID, int wWorkAreaID, int wStationID, OutResult<Integer> wErrorCode){
        Map<Integer,FPCCapacity> wResult = new HashMap<>();
        Map<String, Object> wParams=new HashMap<>();
        wParams.put("ProductID", wProductID);
        wParams.put("FactoryID", wFactoryID);
        wParams.put("WorkshopID", wWorkshopID);
        wParams.put("WorkAreaID", wWorkAreaID);
        wParams.put("StationID", wStationID);
        List<FPCCapacity> wFPCCapacityList=this.SelectPOList(wLoginUser,wParams,FPCCapacity.class, Pagination.getNewMaxSize(),wErrorCode);
        if(wErrorCode.Result!=0||wFPCCapacityList==null|wFPCCapacityList.size()==0)
            return wResult;


        wResult=wFPCCapacityList.stream().collect(Collectors.toMap(p->p.ProductID,p->p,(o1,o2)->o2));

        return wResult;
    }
}
